package com.sphd.education.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.sphd.education.R;
import com.sphd.education.info.ClassifyTwo;
import com.sphd.education.interfaces.RecyclerViewOnCheckChanged;
import com.sphd.education.interfaces.RecyclerViewOnClickListener;

import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 2015/10/16.
 */
public class InterestedLessonAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ClassifyTwo> classifyTwoList;
    private int layoutInt;
    private RecyclerViewOnCheckChanged recyclerViewOnClickListener;

    public InterestedLessonAdapter(Context context, List<ClassifyTwo> classifyTwoList, int layoutInt) {
        this.context = context;
        this.classifyTwoList = classifyTwoList;
        this.layoutInt = layoutInt;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(parent.getContext())
                .inflate(layoutInt, parent, false);
        final ViewClassify viewHold = new ViewClassify(view);
        return viewHold;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        ((ViewClassify) holder).fenlei.setText(classifyTwoList.get(position).getClassify());
        ((ViewClassify) holder).fenlei.setChecked(classifyTwoList.get(position).isLike_lesson());
        ((ViewClassify) holder).fenlei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                recyclerViewOnClickListener.onCheckedChanged(((ViewClassify) holder).fenlei,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return classifyTwoList.size();
    }


    public void setRecyclerViewOnCheckChanged(RecyclerViewOnCheckChanged recyclerViewOnClickListener) {
        this.recyclerViewOnClickListener = recyclerViewOnClickListener;

    }

    class ViewClassify extends RecyclerView.ViewHolder {
        @Bind(R.id.lesson_checkbox)
        CheckBox fenlei;


        public ViewClassify(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }

    }
}
